package com.luxoft.scoremanager.server.model.web;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.luxoft.scoremanager.server.model.dao.ComponentValuesDaoModel;
import com.luxoft.scoremanager.server.model.dao.ScorePackageDaoModel;
import com.luxoft.scoremanager.server.model.dao.StaticDataDaoModel;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;



public class ScorePackage implements Serializable {
    private static final long serialVersionUID = -5170875020617735654L;

    private Integer id;
    private String stage;
    private List<Component> components = new ArrayList<Component>();
    private List<StaticData> staticDatas = new ArrayList<StaticData>();

    public ScorePackage() {

    }

    public ScorePackage(ScorePackageDaoModel scorePackageDaoModel, List<StaticDataDaoModel> staticDataDaoModelList) {
        this.setId(scorePackageDaoModel.getId());
        this.setStage(scorePackageDaoModel.getStage());
        for (ComponentValuesDaoModel componentValuesDaoModel:scorePackageDaoModel.getComponentsValues()){
            this.addComponent(new Component(componentValuesDaoModel));
        }
        for (StaticDataDaoModel staticDataDaoModel:staticDataDaoModelList){
            this.addStaticData(new StaticData(staticDataDaoModel));
        }
    }

    public ScorePackage( String stage) {
        this.stage = stage;
    }

    public ScorePackage(Integer id, String stage) {
        this.id = id;
        this.stage = stage;
    }
    public List<StaticData> getStaticDatas() {
        return staticDatas;
    }

    public void setStaticDatas(List<StaticData> staticData) {
        this.staticDatas = staticData;
    }

    public void addStaticData(StaticData staticData){
        this.staticDatas.add(staticData);
    }

    public void removeStaticData(StaticData staticData){
        if (this.staticDatas.contains(staticData)) {
            this.staticDatas.remove(staticData);
        }
    }

    public List<Component> getComponents() {
        return components;
    }

    public void setComponents(List<Component> components) {
        this.components = components;
    }

    public void addComponent(Component component){
        this.components.add(component);
    }

    public void removeComponent(Component component){
        if (this.components.contains(component)) {
            this.components.remove(component);
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getStage() {
        return stage;
    }

    public void setStage(String stage) {
        this.stage = stage;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ScorePackage)) return false;

        ScorePackage scorePackage = (ScorePackage) o;

        if (!id.equals(scorePackage.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Override
    public String toString() {
        return "Package{" +
                "id=" + id +
                ", stage='" + stage + '\'' +
                '}';
    }

}
